package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.VenueDrawingAudit;
import com.eastfair.venueservice.service.VenueDrawingAuditService;
import com.eastfair.venueservice.vo.VenueDrawingAuditVO;
import com.eastfair.venueservice.vo.VenueDrawingCategoryAuditVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 一键报馆图纸审核
 * </p>
 *
 * @author dq
 * @date 2022-10-31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/venueDrawingAudit")
@Api(value = "VenueDrawingAudit", tags = "一键报馆图纸审核")
@PreAuth(replace = "venueservice:venueDrawingAudit:")
public class VenueDrawingAuditController extends SuperController<VenueDrawingAuditService, Long, VenueDrawingAudit, VenueDrawingAuditPageQuery, VenueDrawingAuditSaveDTO, VenueDrawingAuditUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private VenueDrawingAuditService venueDrawingAuditService;

    @Override
    public void handlerResult(IPage<VenueDrawingAudit> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<VenueDrawingAudit> venueDrawingAuditList = list
                .stream()
                .map((map) -> VenueDrawingAudit.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(venueDrawingAuditList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<VenueDrawingAuditPageQuery> params) {
        VenueDrawingAuditPageQuery pageQuery = params.getModel();
    }

    /**
     * 查询报馆审核图纸VO.
     *
     * @param query the page params
     * @return the r
     */
    @ApiOperation("查询报馆审核图纸VO")
    @PostMapping("/query/venueDrawingAudit")
    public R<List<VenueDrawingAuditVO>> queryVenueDrawingAudit(@RequestBody VenueDrawingAuditDTO query) {
        log.info("queryVenueDrawingAudit - 查询报馆审核图纸VO, query={}", query);
        List<VenueDrawingAuditVO> list = venueDrawingAuditService.listVenueDrawingAuditVO(query);
        return R.successDef(list);
    }
}
